package com.example.roundcornerprogressbar.slice;

import com.example.roundcornerprogressbar.MyApplication;

import com.example.roundcornerprogressbar.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.*;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class MainSlice extends AbilitySlice {
    private HiLogLabel label = new HiLogLabel(HiLog.LOG_APP,1, MyApplication.LOG_TAG);

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        HiLog.info(label, "MainSlice onStart");
        super.setUIContent(ResourceTable.Layout_layout_main_slice);
        initView();
    }

    private void initView() {
        Button btSimple = (Button)findComponentById(ResourceTable.Id_bt_simple);
        btSimple.setClickedListener(component -> {
            Intent simpleIntent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName("com.example.roundcornerprogressbar")
                    .withAbilityName("com.example.roundcornerprogressbar.SimpleAbility")
                    .build();
            simpleIntent.setOperation(operation);
            startAbility(simpleIntent);
        });

        Button btText = (Button)findComponentById(ResourceTable.Id_bt_text);
        btText.setClickedListener(component -> {
            Intent simpleIntent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName("com.example.roundcornerprogressbar")
                    .withAbilityName("com.example.roundcornerprogressbar.TextAbility")
                    .build();
            simpleIntent.setOperation(operation);
            startAbility(simpleIntent);
        });

        Button btIndeterminate = (Button)findComponentById(ResourceTable.Id_bt_indeterminate);
        btIndeterminate.setClickedListener(component -> {
            Intent simpleIntent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName("com.example.roundcornerprogressbar")
                    .withAbilityName("com.example.roundcornerprogressbar.IndeterminateAbility")
                    .build();
            simpleIntent.setOperation(operation);
            startAbility(simpleIntent);
        });

        Button btTabList = (Button)findComponentById(ResourceTable.Id_bt_tablist);
        btTabList.setClickedListener(component -> {
            Intent simpleIntent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName("com.example.roundcornerprogressbar")
                    .withAbilityName("com.example.roundcornerprogressbar.FractionAbility")
                    .build();
            simpleIntent.setOperation(operation);
            startAbility(simpleIntent);
        });
    }
}
